package com.wf.mock.app.mina.app;

import java.util.concurrent.TimeUnit;

import org.apache.mina.core.future.ConnectFuture;
import org.apache.mina.core.service.IoConnector;
import org.apache.mina.core.session.IoSession;

import com.wf.mock.app.mina.ConnectorManager;
import com.wf.mock.app.mina.MessageIntentType;
import com.wf.mock.app.utils.MinaUtils;
import com.wf.mock.app.utils.TokenUtils;

public class MockRenweiguoClient {

	public static void main(String[] args) throws InterruptedException {
		IoConnector connector = ConnectorManager.getAppConnector();
		ConnectFuture connectFuture = connector.connect();

		connectFuture.awaitUninterruptibly();

		IoSession session = connectFuture.getSession();
		session.write(MessageIntentType.APPCONNECT + "{'token':'" + TokenUtils.generateToken("renweiguo@wafertest.com")
				+ "'}");
		
		sendReadMsg(session);

		while (true) {
			TimeUnit.SECONDS.sleep(30);
		}
	}

	
	private static void sendReadMsg(IoSession session) {
		String uuid = MinaUtils.generateUUID();
		String msg = MessageIntentType.APP2PORTAL +"{'userId':'renweiguo','domain':'wafertest.com','operateType':'READMSG','markId':'" + uuid
				+ "','unreadSize':0,'msgId':65678,'sessionId':3858}";
		session.write(msg);
	}

}
